﻿using System.Windows.Media;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace MyFloridaHouse.libSvBingMapsMultiShape
{
    public class MapMultiPolygon : MapMultiShapeBase
    {
        private IList<PointCollection> _projectedPoints;

        // Methods
        public MapMultiPolygon()
            : base(new Path())
        {
        }

        public override IList<PointCollection> ProjectedPoints
        {
            get
            {
                return _projectedPoints;
            }
            set
            {
                _projectedPoints = value;

                if (_projectedPoints != null)
                {
                    PathGeometry polygons = new PathGeometry();

                    foreach(PointCollection pc in _projectedPoints) //loop through each ring
                    {
                        if(!pc[0].Equals(pc[pc.Count - 1])) //check to see if the polygon ring is closed
                        {
                            pc.Add(pc[0]);
                        }

                        PolyLineSegment poly = new PolyLineSegment();
                        poly.Points = pc;

                        PathFigure fig = new PathFigure();
                        fig.StartPoint = pc[0];
                        fig.Segments.Add(poly);

                        polygons.Figures.Add(fig);
                    }

                    //update Path
                    ((Path)base.EncapsulatedShape).Data = polygons;
                }
            }
        }
    }
}
